Adding pathfinding using SDF example#10
Conversation
JeffM2501
left a comment
There was a problem hiding this comment.
Please add a copy of the premake5.lua file to the folder so that it will build with the other examples.
pathfinding_sdf/pathfinding_sdf.c
Outdated
| int pathRatStartX = 5; | ||
| int pathRatStartY = 25; | ||
| int pathRatEndX = 75; | ||
| int pathRatEndY = 25; | ||
| PathfindingNode *mapRat = (PathfindingNode *)MemAlloc(gridWidth * gridHeight * sizeof(PathfindingNode)); | ||
| PathfindingNode *pathRat = (PathfindingNode *)MemAlloc(gridWidth * gridHeight * sizeof(PathfindingNode) * 4); | ||
| int pathRatLength = 0; | ||
| int ratWallFactor = 2; | ||
|
|
||
| // cat setup | ||
| int pathCatStartX = 5; | ||
| int pathCatStartY = 25; | ||
| int pathCatEndX = 75; | ||
| int pathCatEndY = 25; |
There was a problem hiding this comment.
This is a lot of arguments, many that are just X and Y variants.
Can we use vector2 or some other structure to clean this up?
There was a problem hiding this comment.
True. I can create a dedicated struct for each entity. It would be nice if raylib had a Vector2Int... I wanted to keep it integer based (not sure if worth it).
There was a problem hiding this comment.
Everything infernally uses floats, so is there any real benefit to keeping it ints? If you need to you can just call floor on the floats.
There was a problem hiding this comment.
True. It was a decision based on gut feeling. I would keep it for now. I moved the data into structs so I hope it's more organized now.
JeffM2501
left a comment
There was a problem hiding this comment.
The main function is a bit huge, It would be best to break that up into functions with descriptive names.
3b4e978 to
9280336
Compare
|
I reworked it quite a bit and it's now more data oriented. I hope it's also more readable (or at least not less readable). |
|
|
||
| typedef struct Agent | ||
| { | ||
| int startX, startY; |
There was a problem hiding this comment.
I would like to use floats when possible.
|
|
||
| } | ||
|
|
||
| void Agent_findPath(Agent *agent, int enableJumping) |
There was a problem hiding this comment.
this function is huge, can it be broken up more? maybe in places where you have comments, that should be a sub function for readability?
I fear that most people will not be able to follow this code.
No description provided.